package com.example.usercenter.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RedissonConfig {

    @Value("${spring.data.redis.host}")
    private String host;

    @Value("${spring.data.redis.port}")
    private String port;

    @Bean
    public RedissonClient redissonClient() {
        Config config = new Config();
        // 1. 配置redis地址
        config.useSingleServer().setAddress("redis://" + host + ":" + port); //.setPassword("QWEzxc123456");
        // 2. 配置redis所使用的数据库
        config.useSingleServer().setDatabase(1);
        // 3. 创建RedissonClient对象
        return Redisson.create(config);
    }
}
